#!/bin/sh

# 关闭服务，释放系统内存资源

# top | grep com.huawei.*

service_list=$(ps -A -k %mem | grep com.huawei.* | awk '{print $9}')
echo "服务列表: $service_list"

for service in ${service_list}
do
    echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
    echo "关闭服务: $service"
    real_service=(${service//:/ })
    echo "real_service: $real_service"
    service=${real_service[0]}
    am force-stop --user 0 $service
    # pm disable-user --user 0 $service
done


service_list=$(ps -A -k %mem | grep com.google.* | awk '{print $9}')
echo "服务列表: $service_list"

for service in ${service_list}
do
    echo "########################################"
    echo "关闭服务: $service"
    real_service=(${service//:/ })
    echo "real_service: $real_service"
    service=${real_service[0]}
    # pm disable-user --user 0 $service
    am force-stop --user 0 $service
done


service_list=$(ps -A -k %mem | grep com.android.* | awk '{print $9}')
echo "服务列表: $service_list"

for service in ${service_list}
do
    echo "+++++++++++++++++++++++++++++++++++++++"
    echo "关闭服务: $service"
    real_service=(${service//:/ })
    echo "real_service: $real_service"
    service=${real_service[0]}
    # pm disable-user --user 0 $service
    am force-stop --user 0 $service
done